Meredith Brown
Last updated 2019-03-21

In this notebook, I explore the extent to which my city (and specific neighborhood) is plagued by rats and other animals, using 311 Daily Service Requests data from Somerville, MA. This data is available at:

https://data.somervillema.gov/311-Call-Center/311-Daily-Service-Requests/xs7t-pxkc

tl;dr: East Somerville does have more rats than West Somerville (but some areas are definitely worse than others).

I have also annotated this notebook with examples of best practices from the Tidyverse Style Guide, in purple, and my own style tips/tendencies, in green.

Setup

For instructions on how to set up the google maps API for use with ggmap, see this page.

knitr::opts_chunk$set(comment=NA, echo=FALSE, message=FALSE, warning=FALSE)
library(dplyr)
library(tidyr)
library(ggplot2)
library(lubridate) 
library(readr) 
library(ggmap) 

# google maps API setup
#register_google(key = "redacted", write = TRUE) 

Import 311 data from web

all_data <- read_csv(url("https://data.somervillema.gov/api/views/xs7t-pxkc/rows.csv"))

print(all_data, width=Inf, n=5)
# A tibble: 100,447 x 12
  ticket_id issue_type                        ticket_created_date_time
      <dbl> <chr>                             <chr>                   
1    400000 Temporary no parking sign posting 07/01/2015 12:26:00 AM  
2    400006 Temporary no parking sign posting 07/01/2015 08:14:00 AM  
3    400007 Temporary no parking sign posting 07/01/2015 08:20:00 AM  
4    400009 Abandoned property                07/01/2015 08:23:00 AM  
5    400010 Abandoned property                07/01/2015 08:23:00 AM  
  submitter issue_description   ticket_status ticket_last_updated_date_time
      <dbl> <chr>               <chr>         <chr>                        
1     10675 Traffic and Parking Closed        07/01/2015 12:27:00 AM       
2     42994 Traffic and Parking Closed        07/03/2015 04:27:00 PM       
3     42995 Traffic and Parking Closed        04/06/2016 02:23:00 PM       
4     35749 DPW Highway         Closed        07/03/2015 08:43:00 AM       
5     42997 DPW Highway         Closed        07/01/2015 02:55:00 PM       
  secondary_issue_type neighborhood_district ticket_closed_date_time
  <chr>                <chr>                 <chr>                  
1 Service Requests     Ward 1                07/01/2015 12:27:00 AM 
2 Service Requests     <NA>                  07/03/2015 04:27:00 PM 
3 Service Requests     Ward 3                04/06/2016 02:23:00 PM 
4 Service Requests     Ward 2                07/03/2015 08:43:00 AM 
5 Service Requests     Ward 3                07/01/2015 02:55:00 PM 
  location                                                   
  <chr>                                                      
1 "47 Florence St\nSomerville, MA\n(42.3840872, -71.0826777)"
2 "Somerville MA, NA\n(0.0, 0.0)"                            
3 "2 Evergreen Sq\nSomerville, MA\n(42.3865038, -71.1133853)"
4 "36 Rogers Ave\nSomerville, MA\n(42.3966294, -71.1136228)" 
5 "23 Porter St\nSomerville, MA\n(42.3874315, -71.1128601)"  
  street_address
  <chr>         
1 47 Florence St
2 <NA>          
3 2 Evergreen Sq
4 36 Rogers Ave 
5 23 Porter St  
# … with 1.004e+05 more rows